@Echo off
Echo --------------------------------------------------------------------------------
Echo %~f0 %*

:: File: C:\Documents and Settings\paul\My Documents\Src\Batch\set_ANT.cmd
:: Date: 10:56 PM 12/19/2010

:: Requires the current environment to have DelayedExpansion and 
:: CommandExtensions enabled for Current User {HKCU} or Local Machine {HKLM}:
::    reg add "HKCU\Software\Microsoft\Command Processor" /V EnableExtensions  /T REG_DWORD  /d 0x1 /f
::    reg add "HKCU\Software\Microsoft\Command Processor" /V DelayedExpansion  /T REG_DWORD  /d 0x1 /f
    
Set ANT_HOME=
Set ANTCMD=

If /I "%1" equ "latest" "%~0" 181
Call :ChkAnt "%~1" apache-ant-1.8.1 1.8.1 181  apache-ant-1.7.1 1.7.1 171  apache-ant-1.6.5 1.6.5 165

Exit /B

:: ----------------------------------------------------------------------------
:: ----------------------------------------------------------------------------

:: ChkAnt Params:
::    User-supplied cmd line parm, 
::    triplets of directory/version tags.
::       The first tag of the triplet must be the actual directory name
::       The second and third tags are aliases

:ChkAnt
Set PARMS=

:ChkAntLoop
Set PARMS=!PARMS! %2 or %3 or %4 ;
If /I "%~1" equ "%~2" Set ANT_HOME=C:\Program Files\Apache.org\%~2
If /I "%~1" equ "%~3" Set ANT_HOME=C:\Program Files\Apache.org\%~2
If /I "%~1" equ "%~4" Set ANT_HOME=C:\Program Files\Apache.org\%~2
:: If first tag of next triplet is blank, we are done.
:: If we found a HOME, set stuff dependent on HOME.
If "%~5"=="" (
   If "!ANT_HOME!"=="" (
      Echo.
      Echo Looking for a valid ANT version:
      Echo !PARMS!
   ) Else (
      rem :: ANT is a BATCH, not EXE
      Set ANTCMD=!ANT_HOME!\bin\ANT
      Echo ANT_HOME=!ANT_HOME!
      Echo ANTCMD=!ANTCMD!
      "!ANTCMD!" -version
   )
   Exit /B
)
:: Keep %1, scroll next triplet into %2 %3 %4
Shift /2
Shift /2
Shift /2 
Goto :ChkAntLoop

